-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gatsby-transformer-remark): add excerptAst to be exported as a GraphQL field #11237
Conversation
f1c15f4
to
2aa0c3a
Compare
@DSchau Could you help me find why this test |
I have finally figured out that the test added in #10892 did not handle Promises that are passed to |
@chitoku-k so this PR seems to make sense in general. If we have However - if you don't mind me asking, apart from being consistent here, what is this PR solving? |
@DSchau My project currently tries to utilize gatsby-remark-component that requires the AST be passed to its compiler. It works fine so far with |
de6c49b
to
1295a30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! Left a small comment.
Nice catch on the async issue, as well!
`transformer-remark-markdown-excerpt-${format}-${ | ||
node.internal.contentDigest | ||
}-${pluginsCacheStr}-${pathPrefixCacheStr}` | ||
const excerptAstCacheKey = node => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't the excerptCacheKey be used with a format? Instead of two of the same function basically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, does it look better?
@DSchau Any further thoughts for this? |
@chitoku-k checking it out now. Thanks for the reminder! |
I took a look! It looks like the arguments passed to excerpt (e.g. For instance, if we consider the following query, we'd expect the excerpt to be 1 character, as well as the excerpt provided in the AST should be 5 characters. {
allMarkdownRemark(limit:1) {
edges {
node {
excerpt(pruneLength:1)
excerptAst(pruneLength:5)
}
}
}
} This, unfortunately does not seem to be the case! I can dive in in a bit, but I don't believe this to be in a mergeable state quite yet. Would you be able to validate on your end that you're seeing the same? For the record - I used gatsbyjs.org to test! For posterity, here's the result of the above GraphQL query. |
@DSchau Thank you for reviewing and detailed description for the bug! |
… as well partially reverting gatsbyjs#11363
a5b45fd
to
c29290f
Compare
Fixed the regression and rebased to master (due to failures on e2e tests). |
@chitoku-k thank you! I'll take one more look at this, and then hopefully get it merged and published today. Thank you for your patience, and for fixing the issues as they arose! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing some final validations now, but I think this looks good. Will merge in a few unless I find anything!
Thanks!
I appreciate all your reviews! Thanks. |
…12647) ## Description Fixes a bug in `cloneTreeUntil` function in `gatsby-transformer-remark`, where it only returns the last child node. This function is expected to clone a `root` node, but the current implementation forgets to revert the variable back to the `root` node. Reassigning `clonedRoot = newNode` (originally this is the argument `root`) should fix this. By resolving this bug, it appears to correctly returns the entire root node of AST in `excerptAst` of the markdown node, instead of returning the partial result. ## Related Issues Related to #11237
Description
This PR adds/refactors excerpt + excerptAst (which is a new field) because I personally found it incovenient
gatsby-transformer-remark
not exporting an excerpt field in AST. What I did was basically refactoring by splitting out the resolver ofexcerpt
that was internally converting ASTs to HTML to two functions that have similar signatures to thegetHtml()
andgetHtmlAst()
, with some caching feature as well. The tests have been added for these ASTs.Documentation could be added something like this: